'use strict';

// 引入模块
let http = require('http');
let path = require('path');
let url = require('url');
let fs = require('fs');

let workPcth=path.resolve('.')
console.log(workPcth);
let  server=http.createServer((req,res)=>{
    //没读取到具体文件
    res.write('<head><meta charset="utf-8"/></head>');
    let reqPath=req.url;  
  if(reqPath!=='/favicon.ico'){
    
    //完整的路径
    let fullPath=path.join(workPcth,reqPath);
    console.log(fullPath);
    let full=fs.readFileSync(fullPath);
    full.forEach(item => {
        if (item==='index.html') {
            let fileName=path.join(fullPath,item);
            fs.createReadStream(fileName).pipe(res);
        }
    })

}
console.log(fileName);
})
server.listen(3020);
console.log('Server running at http://127.0.0.1:3020/');